#有数据字典
dict1={'name':'Tom','age':20,'gender':'男'}
#空字典
dict2={}

dict3=dict()

#增加字典的数据
dict1['id']=110
print(dict1)    #{'name': 'Tom', 'age': 20, 'gender': '男', 'id': 110}

#删除字典
#1、del()/del:删除字典或删除字典中指定键值对
del dict1['gender']
print(dict1)

#2、clear():清空字典
dict1.clear()
print(dict1)    #{}

#修改字典
#key值查找
dict2={'name':'Tom','age':20,'gender':'男'}
print(dict2['name'])    #Tom
# print(dict1['id'])    #报错

#get():语法 字典.get(key,默认值)
print(dict2.get('name'))    #Tom
print(dict2.get('id',110))    #110
print(dict2.get('id'))     #None

#keys()
print(dict2.keys())     #dict_keys(['name', 'age', 'gender'])

#values()
print(dict2.values())      #dict_values(['Tom', 20, '男'])

#items()
print(dict2.items())       #dict_items([('name', 'Tom'), ('age', 20), ('gender', '男')])

#字典的循环遍历
for key in dict2.keys():
    print(key)

#遍历字典的value
for value in dict2.values():
    print(value)

#遍历字典的元素
for item in dict2.items():
    print(item)

#遍历字典的键值对
for key,value in dict2.items():
    print(f'{key}={value}')

